import java.util.Stack;

public class Main {
    public Stack<Integer> stack;
    public  Stack<Integer> minStack;
    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minStack.empty()) {
            minStack.push(val);
        }else {
            int peekVal = minStack.peek();
            if(val <= peekVal) {
                minStack.push(val);
            }
        }
    }
    public void pop() {
        if(stack.empty()) {
            return;
        }
        int popVal = stack.pop();
        if(popVal == minStack.peek()) {
            minStack.pop();
        }
    }

    public int top() {
        if(stack.empty()) {
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if(minStack.empty()) {
            return -1;
        }
        return minStack.peek();
    }
    public static boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack=new Stack<>();
        int j=0;
        for(int i=0;i<pushV.length;i++){
            stack.push(pushV[i]);
            while(!stack.isEmpty()&&j< popV.length&&stack.peek()==popV[j]){
                stack.pop();
                j++;
            }
        }
        if(!stack.isEmpty()){
            return false;
        }
        return true;
    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for (int i=0;i<tokens.length;i++) {
            if(calculation(tokens[i])){
                int val1=stack.pop();
                int val2=stack.pop();
                switch(tokens[i]){
                    case "+":
                        stack.push(val2+val1);
                        break;
                    case "-":
                        stack.push(val2-val1);
                        break;
                    case "*":
                        stack.push(val2*val1);
                        break;
                    case "/":
                        stack.push(val2/val1);
                        break;
                }
            }else{
                stack.push(Integer.valueOf(tokens[i]));
            }
        }
        return stack.pop();
    }
    private boolean calculation(String s){
        if(s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/")){
            return true;
        }
        return false;
    }

    public boolean isValid(String str) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < str.length(); i++) {
            char s = str.charAt(i);
            if (s == '(' || s == '[' || s == '{') {
                stack.push(s);
            } else {
                if (stack.isEmpty()) {
                    return false;
                }
                char s2 = stack.peek();
                if (s == ')' && s2 == '('
                        || s == '}' && s2 == '{'
                        || s == ']' && s2 == '[') {
                    stack.pop();
                } else {
                    return false;
                }
            }
        }
        //最后判断最后的栈中是否为空，不为空则证明栈中还有元素，则就是不匹配
        if (!stack.isEmpty()) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        int[] pushV={1,2,3,4,5};
        int[] popV={4,5,3,2,1};
        System.out.println(IsPopOrder(pushV,popV));
    }
}